<%@ page import="view.MediaInfo" %>
<%@ page import="model.filemanager.*" %>
<%@ page import="java.util.List" %>
<%@ page import="com.google.appengine.api.datastore.DatastoreService" %>
<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %>
<%@ page import="com.google.appengine.api.datastore.Key" %>
<%@ page import="com.google.appengine.api.datastore.KeyFactory" %>
<%@ page import="com.google.appengine.api.datastore.Entity" %>
<%@ page import="com.google.appengine.api.datastore.EntityNotFoundException" %>
<%@ page import="com.google.appengine.api.blobstore.BlobKey" %>
<%@ page import="com.google.appengine.api.blobstore.BlobstoreService" %>
<%@ page import="com.google.appengine.api.blobstore.BlobstoreServiceFactory" %>
<%@ page import="com.google.appengine.api.blobstore.BlobInfo" %>
<%@ page import="com.google.appengine.api.blobstore.BlobInfoFactory" %>
<%@ page import="com.google.appengine.api.images.ImagesServiceFactory" %>
<%@ page import="com.google.appengine.api.images.ImagesService" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import ="com.google.appengine.api.users.UserService" %>
<%@ page import ="com.google.appengine.api.users.UserServiceFactory" %>

<!DOCTYPE html>
<%
	UserService userService = UserServiceFactory.getUserService();
	User user = userService.getCurrentUser();
    FileManager fm = new FileManager(user.getEmail());
	DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
	MediaInfo mediaInfo = new MediaInfo();
%>
<html>
    <head>
        <title>File Info</title>
        <link rel="stylesheet" type="text/css" href="css/styles.css" />
        <link rel="stylesheet" type="text/css" href="css/formstyles.css" />
    </head>
    <body><div id="maindiv">
    <a href="/">Go to Download List</a><br/><br/>
    <%
    	String key = request.getParameter("key");
    	MediaFile mediaFile = fm.GetFile(key);
    	
    	BlobKey blobKey = new BlobKey(key);
	    BlobstoreService blobStoreService = BlobstoreServiceFactory.getBlobstoreService();
	    BlobInfo blobInfo =  (new BlobInfoFactory(datastore)).loadBlobInfo(blobKey);
	    
	    if(blobInfo.getContentType().contains("image")){
	    	ImagesService imageService = ImagesServiceFactory.getImagesService(); 
	%>
	<img src="<%= imageService.getServingUrl(blobKey,256,false) %>" /></br/> 
	<% 	} 
	%>
	
	<%= mediaInfo.GenerateForm(mediaFile, mediaFile.getType(), true) %>
	<%--Filename: <%= blobInfo.getFilename() %><br/>
	Size: <%= blobInfo.getSize() %> bytes <br/>
	Type: <%= blobInfo.getContentType() %><br/>
	Date Created: <%= blobInfo.getCreation() %><br/> --%>
	
    </div></body>
</html>